﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

using WeatherStation;
using System.Threading;

namespace WeatherStationView
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {

        #region WeatherDataStation Logic

        private WeatherData WeatherStation;
        private const int SleepInterval = 3000;
        private Random rnd;
        private Thread MainThread;

        private void InitWD()
        {
            MainThread = Thread.CurrentThread;

            // Instantiate WD...
            WeatherStation = new WeatherData();

            rnd = new Random();

            Thread WDThread = new Thread(new ThreadStart(this.xStart));
            WDThread.Start();
        }

        public void xStart()
        {
            while (MainThread.IsAlive)
            {
                WeatherStation.SetMeasurements((float)rnd.NextDouble() * 60 - 15, (float)rnd.NextDouble() * 100, (float)rnd.NextDouble() * 1000);
                Thread.Sleep((int)(rnd.NextDouble() * SleepInterval));
            }
        }

        #endregion

        public MainWindow()
        {
            InitializeComponent();

            ///start model...
            InitWD();

            ///set model references...
            MyForecastDisplay.WeatherDataSource = WeatherStation;
            MyStatisticsDisplay.WeatherDataSource = WeatherStation;
            MyCurrentConditionsDisplay.WeatherDataSource = WeatherStation;
            MyHeatIndexDisplay.WeatherDataSource = WeatherStation;
        }

        /*
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            MyStatisticsDisplay.setValues(40, -10, 26.982f);
            MyCurrentConditionsDisplay.setValues(25.989f, 70.09f);
            MyForecastDisplay.setValues(ForecastDisplay.ForecastType.NotChanging);
        }
         * */
    }
}
